package com.atguigu.gulimall.ware.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import javax.sql.DataSource;

/**
 * seata数据源
 * @author weichen
 * @email 519543138@qq.com
 * @date 2022-12-21 下午5:33
 */
@Configuration
public class MySeataConfig {

    @Autowired
    DataSourceProperties properties;

    @Bean
    public DataSource dataSource(DataSourceProperties properties) {
        HikariDataSource dataSource=properties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
        if (StringUtils.hasText(properties.getName())) {
            dataSource.setPoolName(properties.getName());
        }
        return new HikariDataSource(dataSource);
    }
}
